/******************************************************************************* 
 * Copyright (C) 2012-2015 Microfountain Technology, Inc. All Rights Reserved. 
 * 
 * Unauthorized copying of this file, via any medium is strictly prohibited.   
 * Proprietary and confidential
 * 
 * Last Modified: 2015-9-22 17:17:19
 ******************************************************************************/
package cn.cmcc.online.smsapi.sdk.log;
import java.text.SimpleDateFormat;

import android.annotation.SuppressLint;
import android.util.Log;
import cn.cmcc.online.smsapi.sdk.action.AbsSdkDoAction;
import cn.cmcc.online.smsapi.sdk.util.DuoquUtils;

public class LogManager {

    @SuppressLint("SimpleDateFormat")
    private static SimpleDateFormat sdf1 = null;
    public static boolean debug = false;

    public static boolean writeFileLog = false;

    private static synchronized SimpleDateFormat getSdf() {
        if (sdf1 == null) {
            sdf1 = new SimpleDateFormat("yyyy.MM.dd");
        }
        return sdf1;
    }
    /*SDK-550 hewengao 20160719 start*/
    public static String appendStrArr(String... msg){
        if(msg == null){
            return "";
        }
        StringBuilder sb = new StringBuilder();
        for(String s :msg){
            sb.append(s);
            sb.append(" ");
        }
        return sb.toString();
    }
    public static void i(final String tag, final String msg) {
        String message = appendStrArr(msg);
        if (debug) {
            Log.i(tag, message);
        }
    }

    public static void i(final String tag,final Throwable t,final String msg) {
        if (debug) {
            Log.i(tag, msg, t);
        }
    }

    public static void d(final String tag, final Throwable t, final String msg) {
        if (debug) {
            Log.d(tag, msg, t);
        }
    }
    public static void d(final String tag, final String msg1,final String msg2) {
        String message = appendStrArr(msg1,msg2);
        if (debug) {
            Log.d(tag, message);
        }
    }
    public static void d(final String tag, final String msg) {
        String message = appendStrArr(msg);
        if (debug) {
            Log.d(tag, message);
        }
    }

    public static void e(String tag, String msg) {
        if (debug) {
            Log.e(tag, msg);
        }
    }

    public static void e(String tag, String msg, Throwable t) {
        if (debug) {
            Log.e(tag, msg, t);
        }
        /*SDK-699 wangxingjian 20161208 start*/
        /*try {
            AbsSdkDoAction sdkAction = DuoquUtils.getSdkDoAction();
            sdkAction.logError(tag, msg, t);
        } catch (Throwable e) {
            
        }*/
        /*SDK-699 wangxingjian 20161208 end*/
    }

    public static void w(String tag, String msg) {
        if (debug) {
            Log.w(tag, msg);
        }
    }

    public static void w(String tag, String msg, Throwable t) {
        if (debug) {
            Log.w(tag, msg, t);
        }
    }

    // 用于统计流量
    public static void ll(final String tag, final String... msg) {
        String message = appendStrArr(msg);
        if (debug) {
            Log.d(tag, message);
        }
    }
}
